package com.itheima.order.controller;

import com.itheima.order.service.OrderService;
import com.itheima.sh.entity.OrderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //根据用户id查询订单列表
    @GetMapping("/findOrderInfoByUserId/{userId}")
    public List<OrderEntity> findOrderInfoByUserId(@PathVariable("userId") Integer userId){

        System.out.println("findOrderInfoByUserId is called.....");

        // 休眠3s
//        try {
//            Thread.sleep(3000L);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }

        return orderService.findOrderInfoByUserId(userId);
    }

    @PostMapping("findAll")
    public String findAll() {
        return "findAll";
    }


    //添加订单
    @PostMapping("/addOrder")
    public boolean addOrder(@RequestBody OrderEntity orderEntity){
        return orderService.addOrder(orderEntity);
    }


}
